package com.zzyl.controller;

import com.zzyl.base.PageResponse;
import com.zzyl.base.ResponseResult;
import com.zzyl.dto.NursingPlanDto;
import com.zzyl.service.NursingPlanService;
import com.zzyl.vo.NursingPlanVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 护理计划相关接口
 */
@RestController
@RequestMapping("/nursing/plan")
@Api(tags = "护理计划相关接口")
public class NursingPlanController extends BaseController {

    @Autowired
    private NursingPlanService nursingPlanService;

    @GetMapping
    @ApiOperation("查询所有护理计划")
    public ResponseResult<List<NursingPlanVo>> showAllNursingPlan() {
        List<NursingPlanVo> nursingPlanVos = nursingPlanService.showAllNursingPlan();
        return success(nursingPlanVos);
    }

    @GetMapping("/search")
    @ApiOperation("分页查询护理计划")
    public ResponseResult<PageResponse<NursingPlanVo>> queryPage(
            @ApiParam(value = "姓名") String name,
            @ApiParam(value = "当前页") @RequestParam(value = "pageNum", defaultValue = "1") Integer pageNum,
            @ApiParam(value = "每页展示条数") @RequestParam(value = "pageSize", defaultValue = "10") Integer pageSize,
            @ApiParam(value = "状态") Integer status) {
        PageResponse<NursingPlanVo> nursingPlanVoPageResponse = nursingPlanService.queryPage(name, pageNum, pageSize, status);
        return success(nursingPlanVoPageResponse);
    }

    @GetMapping("/{id}")
    @ApiOperation("根据id查询护理计划")
    public ResponseResult<NursingPlanVo> showNursingPlanById(@PathVariable Integer id) {
        NursingPlanVo nursingPlanVo = nursingPlanService.showNursingPlanById(id);
        return success(nursingPlanVo);
    }

    @PostMapping
    @ApiOperation("新增护理计划")
    public ResponseResult addNursingPlan(@RequestBody NursingPlanDto nursingPlanDto) {
        nursingPlanService.addNursingPlan(nursingPlanDto);
        return success();
    }

    @PutMapping("/{id}")
    @ApiOperation("修改护理计划")
    public ResponseResult updateNursingPlan(@PathVariable Integer id,@RequestBody NursingPlanDto nursingPlanDto) {
        nursingPlanService.updateNursingPlan(nursingPlanDto);
        return success();
    }

    @DeleteMapping("/{id}")
    @ApiOperation("根据id删除护理计划")
    public ResponseResult deleteNursingPlan(@PathVariable Integer id) {
        nursingPlanService.deleteNursingPlan(id);
        return success();
    }

    @PutMapping("/{id}/status/{status}")
    @ApiOperation("启用禁用护理计划")
    public ResponseResult updateStatusById(@PathVariable Integer id, @PathVariable Integer status) {
        nursingPlanService.updateStatusById(id,status);
        return success();
    }
}
